package com.weiyun.notebook.Dao

import androidx.lifecycle.LiveData
import com.weiyun.notebook.Entity.Note
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class NoteRepository(private val noteDao: NoteDao) {
    val allNotes:LiveData<List<Note>> =noteDao.getAllNotes()

    suspend fun insert(note: Note){
        withContext(Dispatchers.Default){
            noteDao.insert(note)
        }
    }
    suspend fun update(note: Note) {
        withContext(Dispatchers.Default) {
            noteDao.update(note)
        }
    }

    suspend fun delete(note: Note) {
        withContext(Dispatchers.Default) {
            noteDao.delete(note)
        }
    }
    fun getSpeNotes(content:String):LiveData<List<Note>>{
      return noteDao.getSpeNotes("%$content%")
    }
}